<template>
  <div>
    <van-nav-bar
      title="我的动态"
      left-text="返回"
      right-text="编辑"
      left-arrow
      @click-left="onClickLeft"
      @click-right="toEdit"
    />
    <div v-for="item in myDy" :key="item.index" v-lazy="item">
      <dycard
        :userimage="item.user_face"
        :username="item.user_name"
        :content="item.content"
        :time="$moment(parseInt(item.create_time)).format('YYYY-MM-DD HH:mm')"
        :dy_id="item.dy_id"
        :forwarded="item.forwarded"
        :forward_dy_id="item.forward_dy_id"
        :good="item.good"
        :isShow="isShow"
      ></dycard>
      <van-button type="primary" round @click="toDelete(item.dy_id)"
        >删除</van-button
      >
    </div>
  </div>
</template>

<script>
import dycard from "../../components/dyCard";
import axios from "axios";
export default {
  components: {
    dycard,
  },
  data() {
    return {
      myDy: "",
      isShow: false,
    };
  },
  created() {
    this.getPublished();
  },
  methods: {
    getPublished() {
      axios
        .get(
          `http://localhost:8888/user/published?username=${localStorage.getItem(
            "username"
          )}`
        )
        .then((res) => {
          console.log(res.data);
          this.myDy = res.data;
        });
    },
    onClickLeft() {
      this.$router.go(-1);
    },
    toEdit() {
      this.isShow = true;
    },
    toDelete(dy_id) {
      axios
        .get(`http://localhost:8888/dynamic/deleteById?dy_id=${dy_id}`)
        .then((res) => {
          console.log(res);
          this.getPublished();
        });
    },
  },
};
</script>

<style>
mycard {
  display: inline-block !important;
}
</style>
